package cn.tutu.blockchain.controller;

import java.util.List;

import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.tutu.blockchain.common.MsgObj;
import cn.tutu.shop.entity.Express;
import cn.tutu.shop.service.ExpressService;

@RestController
@RequestMapping("/express")
public class ExpressController {
	private static Logger LOGGER = LoggerFactory.getLogger(RegionController.class);

	@Autowired
	private ExpressService expressService;

	@RequestMapping(value = "/create", method = RequestMethod.POST)
	public MsgObj create(@Valid Express express) {
		LOGGER.info("========创建收货信息:{}======", express.toString());
		expressService.create(express);
		return MsgObj.buildSuccessMsg();
	}

	@RequestMapping("/modify")
	public MsgObj modify(@Valid Express express) {
		LOGGER.info("========修改收货信息：{}======", express.toString());
		expressService.modify(express);
		return MsgObj.buildSuccessMsg();
	}

	@RequestMapping("/remove")
	public MsgObj delete(String id) {
		LOGGER.info("========删除收货信息,ID：{}======", id);
		expressService.remove(id);
		return MsgObj.buildSuccessMsg();
	}

	@RequestMapping("/getGridByUser")
	public MsgObj getGrid(String userId) {

		LOGGER.info("========获取收货地址信息:{}======", userId);
		List<Express> list = expressService.getByUser(userId);

		return MsgObj.buildSuccessObj(list);

	}

}
